package 华为OD机试真题2023.进阶题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import utils.MyUtil;

public class HJ06_分奖金 {
  public static void main(String[] args) throws FileNotFoundException {
    MyUtil.START();
    Solution();
    //    Solution2();
    MyUtil.END();
  }

  static void Solution() throws FileNotFoundException {
    Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/进阶题/input/06.txt"));
    int N = in.nextInt();
    in.nextLine(); // 吸收回车
    //    int[] nums = Arrays.stream(in.nextLine().split("
    // ")).mapToInt(Integer::parseInt).toArray(); //别用这个 stream()，很耗时间。
    String[] sArray = in.nextLine().split(" ");
    int[] nums = new int[sArray.length];
    for (int i = 0; i < sArray.length; i++) {
      nums[i] = Integer.parseInt(sArray[i]);
    }
    int i = 0, j = 0;
    while (i < nums.length) {
      int a = nums[i];
      for (j = i + 1; j < nums.length; j++) {
        int b = nums[j];
        if (b > a) {
          nums[i] = (j - i) * (b - a);
          break;
        }
      }
      i++;
    }

    for (i = 0; i < nums.length; i++) {
      System.out.print(nums[i] + " ");
    }
  }

  static void Solution2() throws FileNotFoundException {
    Scanner sc = new Scanner(new File("src/main/java/华为OD机试真题2023/进阶题/input/06.txt"));
    int n = sc.nextInt();
    sc.nextLine();
    String[] strings = sc.nextLine().split(" ");
    int[] ints = new int[n];
    for (int i = 0; i < n; i++) {
      ints[i] = Integer.valueOf(strings[i]);
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (ints[i] < ints[j]) { // 碰到比自己大数字才进行处理
          ints[i] = (ints[j] - ints[i]) * (j - i);
          break;
        }
      }
    }
    String res = "";
    for (int i : ints) {
      res += i + " ";
    }
    System.out.println(res.substring(0, res.length() - 1));
  }
}
